import json
import matplotlib.pyplot as plt

# 读取 JSON 文件
try:
    with open('optimize_traffic_data.json', 'r') as file:
        data = json.load(file)
except FileNotFoundError:
    print("错误: 文件未找到，请检查文件路径和文件名。")
except json.JSONDecodeError:
    print("错误: JSON 文件格式不正确。")
else:
    # 提取 burst_intensity 和 total_burst 的值
    burst_intensities = []
    total_bursts = []
    for record in data.get("burst", []):
        burst_intensities.append(record["burst_intensity"])
        total_bursts.append(record["total_burst"])

    # 绘制折线图
    plt.plot(burst_intensities, total_bursts, marker='o')

    # 设置图表标题和坐标轴标签
    plt.title('Burst Intensity vs Total Burst')
    plt.xlabel('Burst Intensity')
    plt.ylabel('Total Burst')

    # 显示网格线
    plt.grid(True)

    # 显示图表
    plt.show()
